package tech.yunland.shop.domain.model.report;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 收入分析
 *
 * @author: 袁首京<yuanshoujing@gmail.com> 16/5/12
 */
@Entity
@Table(name = "rpt_income")
public class Income extends AbstractVersionEntity {

	@JSONField(format = "yyyy-MM-dd")
	@Column(name = "biz_date")
	private Date bizDate = new Date(); // 报表日期

	@Column(name = "organ_id")
	private String organId; // 所属机构

	private BigDecimal cash = BigDecimal.ZERO; // 现金收入, 销售单中非会员消费

	private BigDecimal deduction = BigDecimal.ZERO; // 总扣费, 销售单中会员消费

	private BigDecimal charge = BigDecimal.ZERO; // 总充值, 充值收入

	@Transient
	private BigDecimal received; // 总收入 = cash + charge

	public Date getBizDate() {
		return bizDate;
	}

	public void setBizDate(Date bizDate) {
		this.bizDate = bizDate;
	}

	public String getOrganId() {
		return organId;
	}

	public void setOrganId(String organId) {
		this.organId = organId;
	}

	public BigDecimal getCash() {
		return cash == null ? BigDecimal.ZERO : cash;
	}

	public void setCash(BigDecimal cash) {
		this.cash = cash;
	}

	public BigDecimal getDeduction() {
		return deduction == null ? BigDecimal.ZERO : deduction;
	}

	public void setDeduction(BigDecimal deduction) {
		this.deduction = deduction;
	}

	public BigDecimal getCharge() {
		return charge == null ? BigDecimal.ZERO : charge;
	}

	public void setCharge(BigDecimal charge) {
		this.charge = charge;
	}

	public BigDecimal getReceived() {
		received = getCash().add(getCharge());
		return received;
	}
}
